package com.domino.client.view.board;

import com.domino.shared.model.Color;
import com.domino.shared.model.Point;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;

public class BoardButton {
	
	private Image image = new Image();
	private PointClickHandler clickHandler;
	
	BoardButton(BoardGameCallback panel, Point point, String buttonPX) {
		clickHandler = new PointClickHandler(panel, point);
		image.setSize(buttonPX, buttonPX);
		image.addClickHandler(clickHandler);
	}
	
	public Widget getWidget() {
		return image;
	}

	public void setAvailable(Color color) {
		image.setUrl(getAvailableUrl(color));
		clickHandler.acceptEvents(true);
	}

	private String getAvailableUrl(Color color) {
		return color.equals(Color.BLACK)?"imgs/axd44.png":"imgs/aod44.png";
	}

	public void setColor(Color color) {
		image.setUrl(getUrl(color));
		clickHandler.acceptEvents(false);
	}

	private String getUrl(Color color) {
		return color.equals(Color.BLACK)?"imgs/xd44.png":"imgs/od44.png";
	}
	
	private String getLastUrl(Color color) {
		return color.equals(Color.BLACK)?"imgs/last_xd44.png":"imgs/last_od44.png";
	}

	public void setEmpty() {
		image.setUrl("imgs/d44.png");
		clickHandler.acceptEvents(false);
	}

	public void setLastColor(Color color) {
		image.setUrl(getLastUrl(color));
	}

}
